/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

/**
 *
 * @author Reza Ayadi Panah
 */
public class Brewing extends StateC {
    
    protected Brewing(){
        displayStr(" Please wait while brewing ");
    }
    
    @Override
    protected void handle(String event, int data){
        
        if (event.equals("brew")){
            Delay();
            changeState(new DrinkReady());
        }
        else {
            super.handle(event, data);                    //Bytdning af Super
                                                          //To call a superclass constructor.
                                                         //To call a superclass method.

        }
    }
    
    
    
    protected void Delay() {
        

        long currentTime = System.currentTimeMillis();       //Returns the current time in milliseconds.
        long currentTimePlus = currentTime + brew; 
        long dd = 0;
        int counter = 0;  
               
                                          
        displayStr("start brewing");
        
        while (dd < currentTimePlus) {


            dd = System.currentTimeMillis();

            if (dd == currentTime + counter) {
                
               
                 System.out.println("Time left" + ((brew - counter) / (double) 1000) + " sec");
                
                counter += 1000;
            }
        }
    }
    
    
}
